var e = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  t = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../../config/index"),
  a = require("../../../utils/index"),
  r = require("./utils");
Page({
  useStore: function (e) {
    return {}
  },
  data: {
    list: [],
    loading: !1,
    noData: !1,
    hasMore: !1,
    mode: ""
  },
  onTabChange: function (o) {
    var i = this;
    return t(e().mark((function t() {
      var s;
      return e().wrap((function (e) {
        switch (e.prev = e.next) {
          case 0:
            if (o.detail) {
              e.next = 2;
              break
            }
            return e.abrupt("return");
          case 2:
            i.getList()
          case 4:
          case "end":
            return e.stop()
        }
      }), t)
    })))()
  },
  onLoad: function (options) {
    this.setData({
      type: options.type
    })
    var a = this;
    this.setData({
      load:true
    })
    r.onRefresh.call(this, 1).finally((function () {
      a.setData({
        load:false
      })
    }))
  },
  goClock(e) {
    wx.navigateTo({
      url: '/subpackage/clock-in/list/index?id=' + e.currentTarget.dataset.id,
    })
  },
  createAuditor(e) {
    wx.navigateTo({
      url: '/subpackage/auditor/list/index?id='+ e.currentTarget.dataset.id
    })
  },
  onShow: function () {
    console.log('ll')
    var a = this;
    this.setData({
      load:true
    })
    r.onRefresh.call(this, 1).finally((function () {
      a.setData({
        load:false
      })
    }))
  },
  onPullDownRefresh: function () {
    r.onRefresh.call(this, 1).finally((function () {
      wx.stopPullDownRefresh()
    }))
  },
  getList(){
    r.onRefresh.call(this, 1).finally((function () {
      wx.stopPullDownRefresh()
    }))
  },
  goLog(e) {
    wx.navigateTo({
      url: '/subpackage/rent/log-list/index?id=' + e.currentTarget.dataset.id,
    })
  },
  endTent(e) {
    console.log(e)
    wx.showModal({
      title: '提示',
      content: '确认结束项目？',
      complete: (res) => {
        if (res.cancel) {
          console.log('cancel')
        }
        if (res.confirm) {
          $.request['POST/business/engineering/complete/' + e.currentTarget.dataset.id]().then(res => {
            res = res[0]
            if (res.code == 20002) {
              wx.showToast({
                icon:'none',
                title:'项目已结束',
              })
              r.onRefresh.call(this, 1).finally((function () {
                wx.stopPullDownRefresh()
              }))
            } else {
              wx.showToast({
                icon:'none',
                title: res.msg,
              })
            }
          })
        }
      }
    })
  },
  onReachBottom: function () {
    this.data.hasMore || this.data.noData || r.onRefresh.call(this, this.page + 1)
  },
  onToPublish: function () {
    var e = r.tabDescList[this.data.mode].url;
    e && $.router.push(e)
  },
  onMachineTap: function (e) {
    console.log(e)
    if (this.data.type&&this.data.type=='project') {
      $.router.back({
        params: {
          label: "工程项目",
          "select-type": this.data.type,
          value: [{
            id: e.currentTarget.dataset.item.id,
            name: e.currentTarget.dataset.item.engineeringName,
          }]
        }
      });
    } else {
      wx.navigateTo({
        url: '/subpackage/rent/rent-detail/index?id=' + e.currentTarget.dataset.item.id,
      })
    }
  },
  onOperateClick: function (n) {
    var o = this,
      i = this.data.mode,
      s = n.currentTarget.dataset,
      u = s.cardInfo,
      c = s.btnInfo;
    (0, r.handleButtonEvent)(u, c, i, t(e().mark((function t() {
      return e().wrap((function (e) {
        for (;;) switch (e.prev = e.next) {
          case 0:
            a.operateDom.moveToTop().then((function () {
              r.onRefresh.call(o, 1)
            }));
          case 1:
          case "end":
            return e.stop()
        }
      }), t)
    }))))
  },
  onShareGroup: function () {
    this.setData({
      showInvite: !0
    })
  },
  onCloseInvite: function () {
    this.setData({
      showInvite: !1
    })
  },
  onOperateClick(e) {
    var path = e.currentTarget.dataset.path
    wx.navigateTo({
      url: path
    })
  },
  onClickRelease: function () {
    wx.navigateTo({
      url: '/subpackage/rent/add/index',
    })
  }
});